<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
        <meta name="description" content="bootstrap admin template">
        <meta name="author" content="">
        <title>Boss Job login</title>
        <link rel="apple-touch-icon" href="assets/images/apple-touch-icon.png">
        <link rel="shortcut icon" href="../favicon.ico">
        <link href="../_resource/vendor/bootstrap/bootstrap.min.css" rel="stylesheet">
        <link href="../_resource/css/bossjob.style.css" rel="stylesheet">
        <link href='https://fonts.googleapis.com/css?family=Product+Sans:400,400i,700,700i' rel='stylesheet' type='text/css'>
    </head>
    <body>
        <div class="page container" style="">
            <div class="y-login" style="float: none">
                <div class="row">
                    <div class="talent-Login text-center">
                        <span>Admin Login</span>
                    </div>
                    <div class="login-box">
                        <form id="login-form" method="post">
                            <div class="form-group y-account">
                                <div class="">
                                    <input type="text" id="email" name="userid" placeholder="user id" value="" />
                                </div>
                                <span class="error" id="email-error"></span>
                            </div>
                            <div class="form-group y-password">
                                <div class="">
                                    <input type="password" id="password" name="password" placeholder="Password" value="" />
                                </div>
                                <span class="error" id="password-error"></span>
                            </div>
                            <div class="text-right" style="padding: 23px 0 37px 0;">
                                <a href="../Public/reset.html" style="color:#3a73e1;font-weight: 500;">Forgot password ?</a>
                            </div>
                            <div class="">
                                <button id="login" type="button" value="Login" class="btn btn-info" style="width:100%;height: 40px;">Login</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/javascript" src="../_resource/js/Api.js"></script>
        <script type="text/javascript" src="../_resource/vendor/jquery/jquery.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $('#login').click(function () {
                    if ($(this).data('submiting') == 1) {
                        return false;
                    } else {
                        var email = $('#email').val().trim();
                        if (0 == email.length) {
                            $('#email-error').html('Email can not be empty');
                            return false;
                        }
                        if (!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(email)) {
                            $('#email-error').html('Email format error');
                            return false;
                        }
                        $('#email-error').html('');
                        var password = $('#password').val().trim();
                        if (0 == password.length) {
                            $('#password-error').html('Password can not be empty');
                            return false;
                        }
                        $('#password-error').html('');
                        $(this).data('submiting', 1);
                        var _this = $(this);
                        Api.Post('login', {email: email, password: password}, function (object, error) {
                            _this.data('submiting', 0);
                            if (object['data']) {
                                $('#login').css({"background-color":"#999999"}).text('Logining...').attr("disabled",true);
                                Api.set('access', object['data']['access']);
                                Api.set('user', object['data']['user']);
                                window.location.href = '../index.html';
                            } else {
                                alert('Email address or password error.');
                                return false;
                            }
                        });
                    }
                });
            });
            //click enter auto login
            $(document).keydown(function (event) {
                var e = event || window.event;
                if (e && e.keyCode == 13) {
                    $('#login').click();
                }
            });
        </script>
    </body>
</html>
